﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ScrumTime.Models;

namespace ScrumTime.Services
{
    public class UserService
    {
        ScrumTimeEntities _ScrumTimeEntities;

        public UserService(ScrumTimeEntities scrumTimeEntities)
        {
            _ScrumTimeEntities = scrumTimeEntities;
        }

        public static Product GetUserById(ScrumTimeEntities scrumTimeEntities, int id)
        {
            Product product = null;
            var results = from t in scrumTimeEntities.Products
                          where t.ProductId == id
                          select t;
            if (results.Count() > 0)
                product = results.First<Product>();
            else
                product = new Product();
            return product;
            
            //Guid guid = new Guid(id);

            //User user = null;
            //var results = from t in scrumTimeEntities.Users
            //              where t.UserId == guid
            //              select t;

            //if (results.Count() > 0)
            //    user = results.First<User>();
            
            //return user;
        }


        public Product GetProductById(int id)
        {
          //  return GetProductById(_ScrumTimeEntities, id);
            return null;
        }


        public static User GetUserById(ScrumTimeEntities scrumTimeEntities, String id)
        {
            Guid guid = new Guid(id);

            User user = null;
            var results = from t in scrumTimeEntities.Users
                          where t.UserId == guid
                          select t;

            if (results.Count() > 0)
                user = results.First<User>();

            return user;
        }

    }
}